package com.imooc.collection;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * Created by JiaJia on 2019/5/30 0030.
 * 备选课程类
 */
public class ListTest {
    public List courseToSelect;
    public ListTest(){
        this.courseToSelect=new ArrayList();
    }
    public void testAdd(){
        Course cr1=new Course("1","数据结构");
        courseToSelect.add(cr1);
        Course temp=(Course)courseToSelect.get(0);
        System.out.println("添加了课程："+temp.id+"："+temp.name);

        Course cr2=new Course("2","C语言");
        courseToSelect.add(0,cr2);
        Course temp2=(Course)courseToSelect.get(0);
        System.out.println("添加了课程："+temp2.id+"："+temp2.name);
    }


    public void testGet(){
        int size=courseToSelect.size();
        for (int i = 0; i <size ; i++) {
            Course cr=(Course)courseToSelect.get(i);
            System.out.println("课程："+cr.id+":"+cr.name);
        }
    }
    /**
     * 还通过迭代器Iterator来遍历list
     * 或foreach
     */
    public void testModify(){
        courseToSelect.set(1, new Course("3","毛概"));
    }

    /**
     * remove、removeAll删除课程
     * @param args
     */

    public static void main(String[] args) {
        ListTest lt=new ListTest();
        lt.testAdd();
        lt.testGet();
        lt.testModify();
        lt.testGet();
    }
}